<!DOCTYPE html>
<html>
<head>
    <title>简单登录测试</title>
    <meta charset="utf-8">
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 500px;
            margin: 50px auto;
            padding: 20px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
        }
        input {
            width: 100%;
            padding: 8px;
            box-sizing: border-box;
        }
        button {
            background-color: #4CAF50;
            color: white;
            padding: 10px 15px;
            border: none;
            cursor: pointer;
        }
        button:hover {
            background-color: #45a049;
        }
        #result {
            margin-top: 20px;
            padding: 10px;
            border: 1px solid #ddd;
            background-color: #f9f9f9;
        }
        .error {
            color: red;
        }
        .success {
            color: green;
        }
    </style>
</head>
<body>
    <h1>简单登录测试</h1>
    
    <div class="form-group">
        <label for="username">用户名:</label>
        <input type="text" id="username" value="admin">
    </div>
    
    <div class="form-group">
        <label for="password">密码:</label>
        <input type="password" id="password" value="admin123">
    </div>
    
    <button onclick="testLogin()">登录测试</button>
    
    <div id="result"></div>

    <script>
        async function testLogin() {
            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;
            const resultDiv = document.getElementById('result');
            
            resultDiv.innerHTML = '正在测试...';
            
            try {
                const response = await fetch('http://localhost:10001/api/auth/login', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({ username, password })
                });
                
                const data = await response.json();
                
                if (response.ok && data.success) {
                    resultDiv.innerHTML = `<div class="success">登录成功!</div>
                        <div>Token: ${data.data.token.substring(0, 50)}...</div>
                        <div>用户: ${data.data.user.username}</div>
                        
                        <h3>现在测试前端登录页面</h3>
                        <button onclick="testFrontendLogin()">测试前端登录页面</button>`;
                } else {
                    resultDiv.innerHTML = `<div class="error">登录失败: ${data.message || '未知错误'}</div>`;
                }
            } catch (error) {
                resultDiv.innerHTML = `<div class="error">请求错误: ${error.message}</div>`;
            }
        }
        
        async function testFrontendLogin() {
            try {
                // 直接打开前端登录页面
                window.open('http://localhost:10002/login', '_blank');
            } catch (error) {
                document.getElementById('result').innerHTML += `<div class="error">打开前端登录页面失败: ${error.message}</div>`;
            }
        }
    </script>
</body>
</html>